package com.handinfo.android.uicontrols.controls;

import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.utils.Tools;

/**
 * 金钱控件
 * @author handinfo
 */
public class DWMoney extends DWControl
{

	private long m_money = 0; // 金钱数
	private int m_amount[] = new int[3];// 金,银,铜的数量
//	private Bitmap m_img[] = getImg(); // 金银铜的三个图标

	private String m_string1 = "999999金99银99铜";
	private DWFont dwFont = DWFont.getDefaultFont();
	// private float m_strwidth=dwFont.stringWidth("99铜");

	private String m_string[] = { "金", "银", "铜" }; // 暂为测试用代替金钱图标

	DWMoney()
	{
		int w = (int) dwFont.getFontHeight() + 1;
		int h = (int) dwFont.stringWidth(m_string1) + 1;
		setShowWideHigh(w, h);
	}

	DWMoney(int x, int y)
	{
		int w = (int) dwFont.getFontHeight() + 1;
		int h = (int) dwFont.stringWidth(m_string1) + 1;
		setPoint(x, y);
		setShowWideHigh(w, h);
	}

	DWMoney(long money, int x, int y)
	{
		m_money = money;
		int w = (int) dwFont.getFontHeight();
		int h = (int) dwFont.stringWidth(m_string1);
		exchange();
		setPoint(x, y);
		setShowWideHigh(w, h);
	}

//	private Bitmap[] getImg() {
//		// 获取图片资源
//		Bitmap img[] = new Bitmap[3];
//		// ///////////////////////////////////
//		return img;
//	}

	public void render(DWGraphics g)
	{

		g.setColor(-1);
		g.setClip(m_show_x, m_show_y, m_show_w, m_show_h);

		int chang_x = m_show_x + m_show_w;

		for (int i = 3; i > 0; i--) {
			String str = "" + m_amount[i - 1] + m_string[i - 1];
			chang_x -= dwFont.stringWidth(str);
			g.drawString(str, Tools.BLACK, chang_x, m_show_y, Tools.BOTTOM);
		}
	}

	/**
	 * 计算金，银，铜的数量
	 * 
	 */
	private void exchange()
	{
		long ex_money = m_money;
		if (ex_money <= 0)
			return;
		else {
			m_amount[0] = (int) (ex_money / 10000);
			ex_money %= 10000;
			m_amount[1] = (int) (ex_money / 100);
			m_amount[2] = (int) (ex_money % 100);
		}
	}

	public void logic()
	{

	}

	public boolean doClick(float x, float y)
	{
		return false;
	}

}
